<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ShopType extends Model
{
    use HasFactory;

    use HasFactory;
    use SoftDeletes;
    /**商品分类表
     * yangrui
     * @var string
     */
    protected $table='new_shop_type';
    protected $guarded=[];
    protected $fillable=['shop_type_picture','shop_type_name','status'];

    /**
     * Name:多条件搜索列表展示
     * User: yangrui
     * Date: 2023/6/17
     * Time:8:25
     * @param $num
     * @return mixed
     */
    public static function list($num,$search){
        //where（多条件·搜索）
        return self::where('shop_type_name',$search)
                     ->orwhere('status',$search)
                     ->paginate($num);
    }

    /**
     * Name:删除
     * User: yangrui
     * Date: 2023/6/17
     * Time:11:24
     * @param $id
     * @return int
     */
    public static function del($id){
        return self::destroy($id);
    }
    public static function create($data){
        return self::create($data);
    }

    public function categories()
    {
        return $this->hasMany(self::class, 'pid', 'id')->with('categories');
    }
}

